home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / fpc / source / docs / refex / ex49.pp < prev    next >
Encoding:
Text File  |  2000-01-01  |  620 b   |  25 lines

  1. Program Example49;
  2.  
  3. { Program to demonstrate the Random and Randomize functions. }
  4.  
  5. Var I,Count,guess : Longint;
  6.     R : Real;
  7.  
  8. begin
  9.   Randomize; { This way we generate a new sequence every time 
  10.                the program is run}
  11.   Count:=0;
  12.   For i:=1 to 1000 do 
  13.     If Random>0.5 then inc(Count);
  14.   Writeln ('Generated ',Count,' numbers > 0.5');
  15.   Writeln ('out of 1000 generated numbers.');
  16.   count:=0;
  17.   For i:=1 to 5 do
  18.     begin
  19.     write ('Guess a number between 1 and 5 : ');
  20.     readln(Guess);
  21.     If Guess=Random(5)+1 then inc(count);
  22.     end;
  23.   Writeln ('You guessed ',Count,' out of 5 correct.');   
  24. end.
  25.